<?php
namespace app\api\controller;

use think\Db;



header('Access-Control-Allow-Origin:*');
header("Access-Control-Allow-Credentials:true");
header("Access-Control-Max-Age:3600");
header("Access-Control-Allow-Headers:DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Authorization,SessionToken,Token,ID");
header('Access-Control-Allow-Methods: GET, POST, PUT,DELETE,OPTIONS');


class Notice extends Check
{
    protected function _initialize(){
        parent::_initialize();
    }
    /**
     * 公告列表
     */
    public function notice_list()
    {
        $r=Db::name('notice')->where('del_time',null)->order('id desc')->field('del_time',true)->select();
        if($r){
            foreach ($r as $k=>$v) {
                $r[$k]['add_time'] = date('Y-m-d H:i',$v['add_time']);
                $r[$k]['content'] = htmlspecialchars_decode($v['content']);
            }
            return $this->splash(1,'获取成功',$r);
        }else{
            return $this->splash(0,'没有数据');
        }
    }
    /**
     * 公告详情
     */
    public function notice_info()
    {
        if($this->request->isPost()) {
            $data = $this->request->param();
            $r = Db::name('notice')->where('del_time', null)->where('id', $data['id'])->field('del_time', true)->find();
            if ($r) {
                $r['add_time'] = date('Y-m-d H:i', $r['add_time']);
                $r['content'] = str_replace('src=&quot;','src=&quot;'.'http://' . $_SERVER['SERVER_NAME'],$r['content']);
                $r['content'] = htmlspecialchars_decode($r['content']);
                $r['content']=str_replace("<img ",'<img style="width:100%"',$r['content']);
                return $this->splash(1, '获取成功', $r);
            } else {
                return $this->splash(0, '没有数据');
            }
        }else{
            return $this->splash(0, '请求错误');
        }
    }

    /*
     * 轮播图
     * */
    public function banner()
    {
        $r=Db::name('slide')->where('cid',1)->where('status',1)->order('sort desc')->field('image')->select();
        if($r){
            foreach ($r as $k=>$v) {
                $r[$k]['image'] = 'http://' . $_SERVER['SERVER_NAME'].'/public'.$v['image'];
            }
            return $this->splash(1,'获取成功',$r);
        }else{
            return $this->splash(0,'没有数据');
        }
    }
}
